package com.education.user.diaryaspect.controller;

import com.education.auth.entity.BusinessDiaryVo;
import com.education.common.pojo.AjaxResult;
import com.education.user.mapper.BusinessDiaryDao;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/businessDiary")
public class BusinessDiaryController {

    @Autowired
    private BusinessDiaryDao businessDiaryDao;

    /**
     *
     * @param businessDiaryVo
     * @return
     */
    @PostMapping("/diaryAdd")
    public int diaryAdd(@RequestBody BusinessDiaryVo businessDiaryVo) {
        int insertRes = businessDiaryDao.insert(businessDiaryVo);
        return insertRes;
    }

    /**
     *  日志查询接口
     * @param opeType 区分登录与其他操作 1|2
     * @param keyWord 关键词搜索
     * @param timeStart 时间段
     * @param opeTypeValue 操作类型（1查询、2添加、3修改、4删除、5导入、6导出）
     * @return
     */
    @GetMapping("/diarySelect")
    public AjaxResult diarySelect(@RequestParam(value = "opeType",required = true) String opeType,
                                                 @RequestParam(value = "keyWord",required = false) String keyWord,
                                                 @RequestParam(value = "timeStart",required = false)String timeStart,
                                                 @RequestParam(value = "timeEnd",required = false)String timeEnd,
                                                 @RequestParam(value = "opeTypeValue",required = false)String opeTypeValue,
                                                 Integer pageNum, Integer pageSize) {
        //处理时间段格式
        //if (timeStart != null && timeEnd !=null) {
        //    timeStart = timeStartEnd[0];
        //    timeEnd = timeStartEnd[1];
        //}
        //需要分页查询
        if (pageNum != null && pageSize != null){
            PageHelper.startPage(pageNum,pageSize);
        }
        //查询业务
        List<BusinessDiaryVo> businessDiaryVoList = businessDiaryDao.diarySelect(opeType, keyWord, timeStart, timeEnd, opeTypeValue);
        return AjaxResult.success(new PageInfo<BusinessDiaryVo>(businessDiaryVoList));
    }

}
